package com.xdkj.commons.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.apache.commons.dbutils.QueryRunner;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * ClassName RunnerUtil
 * Description:
 *
 * @Author:一尘
 * @Version:1.0
 * @Date:2021-11-02-9:41
 */
public class RunnerUtil {

    public static QueryRunner getRunner() {
        InputStream resourceAsStream = RunnerUtil.class.getClassLoader().getResourceAsStream("db.properties");
        Properties properties = new Properties();
        DataSource dataSource = null;
        try {
            properties.load(resourceAsStream);
            dataSource = DruidDataSourceFactory.createDataSource(properties);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new QueryRunner(dataSource);
    }
}
